<?php
/*
 * @author : Pham Huu Sam
 * @phone : 0922.926.269
 */
class Home extends CI_Controller{
    //put your code here
    public function  __construct() {
        parent::__construct();
        $this->load->library("my_layout"); // Sử dụng thư viện layout
        $this->my_layout->setLayout("layout/frontend"); // load file layout chính (view/layout/frontend.php)
		$this->load->Model("Mtintuc");
		$this->load->model('Mconfig');
		$this->load->library('pagination');		
        $this->load->helper("text"); 
		$this->load->library('session');
    }
	
    // Controller mặc định cho trang chủ
    public function index() {
        $data['title'] = "Trang chủ";
        $data['TieuDe'] = "WELCOME TO HOSREM";

		$mUriSegment3        =""; 
		$mNumbersegment      = 2; //Segment content paging..default  link = 'news/thongtin'
		$uri = $this->uri->segment(2);

		if($uri != null && $mParseIntUri==0) {
			$mNumbersegment = 3;
			$mUriSegment3 = $uri;
		}	
		else{
			$mNumbersegment = 2;
			$mUriSegment3   = '';
		}	
		

		//Config pagging.
		// 3 case can happen.
		$urlPage = 'gioithieu';
		if($mUriSegment3 !='') {
			$urlPage .= $mUriSegment3;
		}

		$config['base_url']    = base_url($urlPage); // xác định trang phân trang 
		$config['total_rows']  = $this->Mtintuc->CountRecordTinTucPaging(); // xác định tổng số record 
		$configFrontEnd = $this->Mconfig->get_One();
        $config['per_page'] = $configFrontEnd->cf_PageSize; // xác định số record ở mỗi trang

		if($this->uri->segment($mNumbersegment) == null) {
			$mFromRecord  = 0;
			$config['uri_segment'] = 0;
		} else {
			$mFromRecord  = ($this->uri->segment($mNumbersegment));
			$config['uri_segment'] = $mNumbersegment; // xác định segment chứa page number  
		}

		$this->pagination->initialize($config);
		$data['danhsachtintuc'] = $this->Mtintuc->GetTinTucPaging($config['per_page'], $mFromRecord); 

        $this->my_layout->view("frontend/home",$data);
    } 

}
?>